﻿package problems.producerconsumer;
import java.util.LinkedList;
import java.util.Queue;

import helpers.IAction;

public abstract class AbstractProducerConsumer
{
	/**
	 * A queue of actions that have been produced
	 */
    private final Queue<IAction> buffer = new LinkedList<IAction>();
	
    public Queue<IAction> getBuffer() {
    	return buffer;
    }
    
    /**
     * Invokes an action from the queue if there is one.
     * If there aren't any actions to perform, a thread will have to wait.
     * As soon as a producer thread has signaled it has produced something (added something to the queue)
     * the consumer will dequeue the action from the buffer and invoke it.
     */
    public abstract void consume();

    /**
     * Adds an action to perform on the queue.
     * @param action The action to add to the buffer
     */
    public abstract void produce(IAction action);
}